package Dynamic_programming;

/**
 * @Author 万家欣
 * @Date 2022/4/8 14:16
 * @Version 1.0
 */
class NumArray {
    int[] temp ;
    int [] t;
    public NumArray(int[] nums) {
        temp = new int[nums.length];
        temp[0] = nums[0];
        for (int i = 1; i <nums.length ; i++) {
            temp[i] = temp[i - 1] + nums[i];
        }
         t = nums;
    }

    public void update(int index, int val) {
        int v = t[index];
        t[index] = val;
        for (int i = index; i < t.length; i++) {
            temp[i] = temp[i] - v + val;
        }
    }

    public int sumRange(int left, int right) {
        return temp[right] - temp[left];
    }
}